package com.gph.saviorframework.mq.service.impl;

import com.alibaba.rocketmq.common.protocol.body.KVTable;
import com.alibaba.rocketmq.tools.admin.DefaultMQAdminExt;
import com.alibaba.rocketmq.tools.command.broker.BrokerStatusSubCommand;
import com.gph.saviorframework.mq.service.BrokerService;
import com.gph.saviorframework.mq.service.impl.validate.CmdTrace;

/**
 * Created by root on 16-7-18.
 */
public class BrokerServiceImpl extends AbstractService implements BrokerService {

    @CmdTrace(cmdClazz = BrokerStatusSubCommand.class)
    public KVTable getKVTable(String brokerAddr){
        DefaultMQAdminExt defaultMQAdminExt = getDefaultMQAdminExt();
        try{
            defaultMQAdminExt.start();
            return defaultMQAdminExt.fetchBrokerRuntimeStats(brokerAddr);
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
        finally {
            shutdownDefaultMQAdminExt(defaultMQAdminExt);
        }
        return null;
    }
}
